package com.jiantong.work.impl.service;


import com.google.common.base.Throwables;
import com.jiantong.user.ext.LoginUser;
import com.jiantong.work.impl.manager.BreedReportManager;
import com.jiantong.work.model.BreedReport;
import com.jiantong.work.model.BreedReportSurveyRecord;
import com.jiantong.work.service.BreedReportSurveyRecordWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by niufei on 2017/3/15.
 *
 */
@Slf4j
@Service
@RpcProvider
public class BreedReportSurveyRecordWriteServiceImpl implements BreedReportSurveyRecordWriteService{

    private final BreedReportManager breedReportManager;

    @Autowired
    public BreedReportSurveyRecordWriteServiceImpl(BreedReportManager breedReportManager) {
        this.breedReportManager = breedReportManager;
    }

    @Override
    public Response<Map<String , Object>> save(BreedReport breedReport , BreedReportSurveyRecord breedReportSurveyRecord, Integer toStatus) {
        try{
            return Response.ok(breedReportManager.updateBreedReportAndSurveyRecord(breedReport,breedReportSurveyRecord,toStatus));
        }catch (Exception e){
            log.error("failed to create breedReportSurveyRecord error :{}", Throwables.getStackTraceAsString(e));
            return Response.fail("breedReportSurveyRecord.create.failed");
        }
    }
}
